const app = getApp()
Page({
  data: {
    imageXuanzhuan: true,
    renderObj: [],
    // reqData: {
    //   id: sessionStorage.id,
    //   type: type,
    //   pageno: 1,
    //   pagesize: 50
    // },
    type: '',
    page: '',
    pageno: 1,
    pageCount: ''
  },
  perDetails: function (e) {//跳转到用户详情
    var userid = e.currentTarget.dataset.userid;
    wx.navigateTo({
      url: '../../pages/memberDetails/memberDetails?userid=' + userid,
    })
  },
  onLoad: function (opt) {
    var _this = this;
    // var initType=opt.type;
    // wx.setNavigationBarTitle({
    //   title: '每日速配',
    // });
    this.initPage(opt);
  },
  onReady: function () {
    this.hiDialog = this.selectComponent('#hiDialog');
    this.msgDialog = this.selectComponent('#msgDialog');
  },
  initPage: function (opt) {
    var _this = this;
    var reqType = opt.type == undefined ? this.data.type : opt.type;
    var page = opt.page == undefined ? this.data.page : opt.page;
    var url = page == 1 ? app.globalData.SERVICE.USERCENTER.USER_LIST : app.globalData.SERVICE.USERCENTER.GREET_LIST;
    var reqData = {
      'id': app.globalData.userid,
      'type': reqType,
      'pageno': _this.data.pageno,
      'pagesize': 50
    }
    var _this = this;
    app.doReq(url, reqData, 'GET', function (res) {

      if (_this.data.pageno == 1) {
        _this.setData({
          renderObj: res.data.pageitems,
          type: reqType,
          page: page,
          pageCount: res.data.pagecount,
        });
      } else {
        _this.setData({
          renderObj: _this.data.renderObj.concat(res.data.pageitems),
        });
      }
    });
  },
  onReachBottom: function () {//刷新
    var _this = this;
    var currentPageNo = _this.data.pageno;
    if (currentPageNo <= _this.data.pageCount) {
      _this.data.pageno++;
      _this.initPage({});
    }
  },
  sayhi: function (e) {
    console.log(e);
    wx.setStorageSync('mateid', e.currentTarget.dataset.mateid);
    this.hiDialog.show()
  },
  sendMsg(e) {
    console.log(e);
    wx.setStorageSync('mateid', e.currentTarget.dataset.mateid);
    this.msgDialog.show(1);
  },
  onReachBottom: function () {//刷新
    var _this = this;
    var currentPageNo = _this.data.pageno;
    if (currentPageNo <= _this.data.pageCount) {
      _this.data.pageno++;
      _this.initPage({});
    }
  },
});